﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Pay.Data {
    public partial class OrderMap
        : System.Data.Entity.ModelConfiguration.EntityTypeConfiguration<Order> {
        public OrderMap() {
            // table
            ToTable("mc_Order", "dbo");

            // keys
            HasKey(t => t.Id);

            // Properties
            Property(t => t.Id)
                .HasColumnName("Id")
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity)
                .IsRequired();
            Property(t => t.OrderNo)
                .HasColumnName("OrderNo")
                .HasMaxLength(50)
                .IsRequired();
            Property(t => t.MerchantId)
                .HasColumnName("MerchantId")
                .IsRequired();
            Property(t => t.PayId)
                .HasColumnName("PayId")
                .IsRequired();
            Property(t => t.BuyId)
                .HasColumnName("BuyId")
                .IsOptional();
            Property(t => t.Remark)
                .HasColumnName("Remark")
                .IsOptional();
            Property(t => t.OrderTime)
                .HasColumnName("OrderTime")
                .IsRequired();
            Property(t => t.FinishTime)
                .HasColumnName("FinishTime")
                .IsOptional();
            Property(t => t.Status)
                .HasColumnName("Status")
                .IsRequired();
            Property(t => t.DiscountName)
                .HasColumnName("DiscountName")
                .IsOptional();
            Property(t => t.DiscountAmount)
                .HasColumnName("DiscountAmount")
                .HasPrecision(18, 2)
                .IsOptional();
            Property(t => t.Freight)
                .HasColumnName("Freight")
                .HasPrecision(18, 2)
                .IsRequired();
            Property(t => t.OrderAmount)
                .HasColumnName("OrderAmount")
                .HasPrecision(18, 4)
                .IsRequired();
            Property(t => t.DisAmount)
                .HasColumnName("DisAmount")
                .HasPrecision(18, 4)
                .IsRequired();
            Property(t => t.Points)
                .HasColumnName("Points")
                .IsRequired();
            Property(t => t.ShippingType)
                .HasColumnName("ShippingType")
                .IsRequired();
            Property(t => t.Integral)
                .HasColumnName("Integral")
                .IsOptional();
            Property(t => t.IntegralDiscount)
                .HasColumnName("IntegralDiscount")
                .HasPrecision(18, 2)
                .IsOptional();
            Property(t => t.PayAmount)
                .HasColumnName("PayAmount")
                .HasPrecision(18, 4)
                .IsRequired();
            Property(t => t.FeeAmount)
                .HasColumnName("FeeAmount")
                .HasPrecision(18, 6)
                .IsRequired();
            Property(t => t.Fee)
                .HasColumnName("Fee")
                .HasPrecision(18, 2)
                .IsRequired();
            Property(t => t.Amount)
                .HasColumnName("Amount")
                .HasPrecision(18, 6)
                .IsRequired();
            Property(t => t.Binds)
                .HasColumnName("Binds")
                .IsOptional();
            Property(t => t.Tax)
                .HasColumnName("Tax")
                .IsOptional();
            Property(t => t.PostFee)
                .HasColumnName("PostFee")
                .IsOptional();
            Property(t => t.SinoFee)
                .HasColumnName("SinoFee")
                .IsOptional();
            Property(t => t.DistributionId)
                .HasColumnName("DistributionId")
                .IsOptional();
            Property(t=>t.ShopId)
                .HasColumnName("ShopId")
                .IsOptional();

            Property(t => t.RedDrill)
                  .HasPrecision(18, 6)
                  .IsRequired();

            // Relationships
            HasRequired(t => t.Merchant)
                .WithMany()
                .HasForeignKey(d => d.MerchantId)
                .WillCascadeOnDelete(false);
            HasOptional(t => t.Buyer)
                .WithMany()
                .HasForeignKey(d => d.BuyId)
                .WillCascadeOnDelete(false);
            HasRequired(t => t.PayInfo)
				.WithMany(t=>t.Orders)
	            .HasForeignKey(d => d.PayId)
	            .WillCascadeOnDelete(false);
        }
    }

    public partial class OrderRefundMap
        : System.Data.Entity.ModelConfiguration.EntityTypeConfiguration<OrderRefund> {
        public OrderRefundMap() {
            // table
            ToTable("mc_OrderRefund", "dbo");

            // keys
            HasKey(t => t.Id);

            // Properties
            Property(t => t.Id)
                .HasColumnName("Id")
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity)
                .IsRequired();

            HasRequired(t => t.Order)
                .WithMany()
                .HasForeignKey(d => d.OrderId)
                .WillCascadeOnDelete(false);
            HasRequired(t => t.Merchant)
                .WithMany()
                .HasForeignKey(t => t.MerchantId)
                .WillCascadeOnDelete(false);
        }
    }
}
